//
//  ReadMainScrollView.m
//  product_B
//
//  Created by lanou on 16/5/28.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ReadMainScrollView.h"
@interface ReadMainScrollView()<UIScrollViewDelegate>
@property (nonatomic,assign)NSInteger index;
@end
@implementation ReadMainScrollView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.pagingEnabled = YES;
        
        
        self.delegate = self;
        self.contentSize = CGSizeMake(10 * self.frame.size.width, self.frame.size.height);
    }
    return self;
}
- (void)setReadMainModelWithArray:(NSMutableArray *)modelArray{
    if (_smallScrollArray.count!=0) {
        for (ReadSmallScrollView *smallView  in _smallScrollArray) {
            [smallView removeFromSuperview];
        }
    }
    self.modelArray = modelArray;
    self.smallScrollArray = [NSMutableArray array];
    for (int i = 0; i<10; i++) {
        _smallScrollView = [[ReadSmallScrollView alloc]initWithFrame:CGRectMake(self.frame.size.width * i, 0, self.frame.size.width, self.frame.size.height)];
        _smallScrollView.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height + 150);
        _smallScrollView.modelArray = self.modelArray[i];
        _smallScrollView.index = i;
        [self addSubview:_smallScrollView];
        [_smallScrollArray addObject:_smallScrollView];
    }
   
    
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
//    if (_index == 1) {
//        if (_readScrollDelegate && [_readScrollDelegate respondsToSelector:@selector(scrollViewRequestWork)]) {
//            [_readScrollDelegate scrollViewRequestWork];
//        }
//    }
//    _index = 0;
    if (self.contentOffset.x < 0) {
        if (_readScrollDelegate && [_readScrollDelegate respondsToSelector:@selector(scrollViewRequestWork)]) {
                        [_readScrollDelegate scrollViewRequestWork];
                    }
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (self.contentOffset.x > 9 * kWidth) {
        if (_readScrollDelegate && [_readScrollDelegate respondsToSelector:@selector(pushReadEverController)]) {
            [_readScrollDelegate pushReadEverController];
        }
    }
//    if (self.contentOffset.x < -70) {
//        _index = 1;
//    }
    
}
@end
